package com.angrysnail.cloud.test.client;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {
	@Autowired
	private DiscoveryClient client;

	@RequestMapping(value = "/hello", method = RequestMethod.GET)
	public String index() {
		List<String> serviceIds = client.getServices();
		for (String id : serviceIds) {
			System.out.println(id);
		}
		List<ServiceInstance> instances = client.getInstances("hello-service1");
		for (ServiceInstance serviceInstance : instances) {
			Map<String, String> metaData = serviceInstance.getMetadata();
			System.out.println(metaData);
		}
		System.out.println(instances.size());
		return "HelloWorld=================";
	}
}